package com.atguigu.realtime.util;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;

/**
 * @Author lizhenchao@atguigu.cn
 * @Date 2021/11/23 10:03
 */
public class AtguiguUtil {
    public static <T> List<T> toList(Iterable<T> it) {
        List<T> list = new ArrayList<>();
        for (T t : it) {
            list.add(t);
        }
        
        return list;
    }
    
    public static Long toTs(String dateTime, String... format) {
        String f = "yyyy-MM-dd HH:mm:ss";  // 默认的日期格式
        if (format.length > 0) {
            f = format[0];
        }
        try {
            return new SimpleDateFormat(f).parse(dateTime).getTime();
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return null;
    }
    
    public static String toDateTimeString(long ts, String... format) {
        String f = "yyyy-MM-dd HH:mm:ss";  // 默认的日期格式
        if (format.length > 0) {
            f = format[0];
        }
        return new SimpleDateFormat(f).format(ts);
    }
}
